﻿Imports System.Data.OleDb
Public Class uploadcar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles tb_ModelName.TextChanged

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newfileloc As String
        If fub_picture.HasFile Then
            newfileloc = Request.MapPath("pictures")
            newfileloc = newfileloc & "/" & fub_picture.FileName
            fub_picture.SaveAs(newfileloc)
        Else
            Return
        End If






        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("CarsConn").ConnectionString)
        Dim sql As String = "INSERT INTO ClassicCars (ModelName,ModelYear,CC,Make,Condition,Color,Registration,Price,ContactNumber,Picture,InfoUrl,SellerPostCode) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12)"
        Dim cmd As New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", tb_ModelName.Text)
        cmd.Parameters.AddWithValue("@f2", CInt(tb_modelyear.Text))
        cmd.Parameters.AddWithValue("@f3", CInt(tb_cc.Text))
        cmd.Parameters.AddWithValue("@f4", tb_make.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Condition.Text)
        cmd.Parameters.AddWithValue("@f6", tb_color.Text)
        cmd.Parameters.AddWithValue("@f7", tb_Registration.Text)
        cmd.Parameters.AddWithValue("@f8", CInt(tb_Price.Text))
        cmd.Parameters.AddWithValue("@f9", tb_ContactNumber.Text)
        cmd.Parameters.AddWithValue("@f10", "pictures/" & fub_picture.FileName)
        cmd.Parameters.AddWithValue("@f11", tb_InfoUrl.Text)
        cmd.Parameters.AddWithValue("@f12", tb_SellerPostCode.Text)
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("Default.aspx")





    End Sub
End Class